import com.ms.com.*;
import com.ms.wfc.data.*;  

/**
 * This class can take a variable number of parameters on the command
 * line. Program execution begins with the main() method. The class
 * constructor is not invoked unless an object of type 'Class1'
 * created in the main() method.
 */
public class Class1
{
	/**
	 * The main entry point for the application. 
	 *
	 * @param args Array of parameters passed to the application
	 * via the command line.
	 */
	public static void main (String[] args)
	{
		System.out.println ( "DSN Connection to ODBC Drivers:\n" );

		System.out.println ( "Access ODBC Driver..." );
		{
		    // This code assumes that the ODBC Data Source OLE_DB_NWind_Jet
		    // was created by the installation of the DATA ACCESS 2.0 SDK

		    // Access ODBC Driver via DSN
		    Con1_Open( "PROVIDER=MSDASQL;" +
		               "DSN=OLE_DB_NWind_Jet;" +
		               "UID=admin;PWD=;" );

		    Con1_Open( "DSN=OLE_DB_NWind_Jet;" +
		               "UID=admin;PWD=;" );

		    // Access ODBC Driver via DSN using ADO Syntax
		    // Note use of DATA SOURCE=, USER ID=, and PASSWORD= clauses
		    Con1_Open( "PROVIDER=MSDASQL;" +
		               "DATA SOURCE=OLE_DB_NWind_Jet;" +
		               "USER ID=admin;PASSWORD=;" );

		    Con1_Open( "DATA SOURCE=OLE_DB_NWind_Jet;" +
		               "USER ID=admin;PASSWORD=;" );
		}

		System.out.println ( "Oracle ODBC Driver..." );
		{
		    // This code assumes you have Oracle Client software installed,
		    // that you have an oracle Server named "dseOracle8" and that
		    // you have an ODBC Data Source named "dseOracleDSN" that
		    // references this server.
    
		    // Oracle ODBC Driver via DSN
		    Con1_Open ("PROVIDER=MSDASQL;" +
		              "DSN=dseOracleDSN;" +
		              "UID=demo;PWD=demo;" );
    
		    Con1_Open ("DSN=dseOracleDSN;" +
		              "UID=demo;PWD=demo;" );
    
		    // Oracle ODBC Driver via DSN using ADO Syntax
		    // Note use of DATA SOURCE=, USER ID=, and PASSWORD= clauses
		    Con1_Open ("PROVIDER=MSDASQL;" +
		              "DATA SOURCE=dseOracleDSN;" +
		              "USER ID=demo;PASSWORD=demo;" );
    
		    Con1_Open ("DATA SOURCE=dseOracleDSN;" +
		              "USER ID=demo;PASSWORD=demo;" );
		}

		System.out.println ( "SQL Server ODBC Driver..." );
		{
		    // This code assumes you have SQL Server installed with
		    // an ODBC Data Source named "LocalServer"
  
		    // SQL Server ODBC Driver via DSN
		    Con1_Open ("PROVIDER=MSDASQL;" + 
		              "DSN=LocalServer;database=Master;" +
		              "UID=sa;pwd=;" );
		          
		    Con1_Open ("DSN=LocalServer;database=Master;" +
		              "UID=sa;pwd=;" );
		          
		    // SQL Server ODBC Driver via DSN using ADO syntax
		    // Note use of DATA SOURCE=, INITIAL CATALOG=, USER ID=, and PASSWORD= clauses
		    Con1_Open ("PROVIDER=MSDASQL;" +
		              "DATA SOURCE=LocalServer;INITIAL CATALOG=pubs;" +
		              "USER ID=sa;PASSWORD=;" );
    
		    Con1_Open ("DATA SOURCE=LocalServer;INITIAL CATALOG=pubs;" +
		              "USER ID=sa;PASSWORD=;" );
		}

		System.out.println ( "\nDSN-Less Connection String to ODBC Drivers:\n" );

		System.out.println ( "Access ODBC Driver..." );
		{
		    // This code assumes you have the NWIND access database
		    // in a path C:\_data

		    //  Access ODBC Driver via DSN-Less
		    Con1_Open ("PROVIDER=MSDASQL;" +
		              "DRIVER={Microsoft Access Driver (*.mdb)};" +
		              "DBQ=C:\\_data\\NWind.mdb;" +
		              "UID=sa;PWD=;" );

		    Con1_Open ("DRIVER={Microsoft Access Driver (*.mdb)};" +
		              "DBQ=C:\\_data\\NWind.mdb;" +
		              "UID=sa;PWD=;" );
		}

		System.out.println ( "Oracle ODBC Driver..." );
		{
		    // This code assumes you have Oracle Client software installed,
		    // that you have an oracle Server named "dseOracle8"
   
		    //  Oracle ODBC Driver
		    Con1_Open ("PROVIDER=MSDASQL;" +
		              "DRIVER={Microsoft ODBC for Oracle};" +
		              "SERVER=dseOracle8;" +
		              "UID=demo;PWD=demo;" );

		    Con1_Open ("DRIVER={Microsoft ODBC for Oracle};" +
		              "SERVER=dseOracle8;" +
		              "UID=demo;PWD=demo;" );
		}

		System.out.println ( "SQL Server ODBC Driver..." );
		{
		    // This code assumes you have SQL Server named "zhadumnt"

		    //  SQL Server ODBC Driver
		    Con1_Open ("PROVIDER=MSDASQL;" +
		              "DRIVER={SQL Server};" + 
		              "SERVER=zhadumnt;DATABASE=pubs;" +
		              "UID=sa;PWD=;" );

		    Con1_Open ("DRIVER={SQL Server};" +
		              "SERVER=zhadumnt;DATABASE=pubs;" +
		              "UID=sa;PWD=;" );
		}

		System.out.println ( "\nConnection String to Native OLE DB Providers:\n" );

		System.out.println ( "Jet OLE DB Native Provider..." );
		{
		    // This code assumes you have the NWIND access database
		    // in a path C:\_data

		    // Access Provider
		    // NOTE:  UID and PWD syntax cannot be used here
		    Con1_Open ("PROVIDER=Microsoft.Jet.OLEDB.4.0;" +
		              "DATA SOURCE=C:\\_data\\NWind.mdb;" +
		              "USER ID=admin;PASSWORD=;" );
		}

		System.out.println ( "Oracle OLE DB Native Provider..." );
		{
		    // This code assumes you have Oracle Client software installed,
		    // that you have an oracle Server named "dseOracle8"

		    //  Oracle Provider
		    Con1_Open ("PROVIDER=MSDAORA;" +
		              "DATA SOURCE=dseOracle8;" +
		              "USER ID=demo;PASSWORD=demo;" );
		}

		System.out.println ( "SQL Server OLE DB Native Provider..." );
		{
		    // This code assumes you have SQL Server named "zhadumnt"
    
		    //  SQL Server Provider
		    Con1_Open ("PROVIDER=SQLOLEDB;" +
		              "DATA SOURCE=zhadumnt;DATABASE=pubs;" +
		              "USER ID=sa;PASSWORD=;" );
    
		    //  SQL Server Provider (using ODBC Syntax)
		    Con1_Open ("PROVIDER=SQLOLEDB;" +
		              "DSN=zhadumnt;DATABASE=pubs;" +
		              "UID=sa;PWD=;" );
		}
	}
	
	public static void Con1_Open( String strConnectString )
	{
		Connection conn1 = null;

		try
		{
			conn1 = (Connection)new Connection();
			conn1.setConnectionString( strConnectString );
			conn1.open( "", "", "", -1 );
			conn1.close();
			
			System.out.println( "\t...Success!" );
		}
        catch (com.ms.com.ComFailException e)    
        {
			System.out.println( "\t...Oops!  Failed to connect! (comFailException)" );
        }
        catch(Exception e) 
		{
			System.out.println( "\t...Oops!  Failed to connect! (Exception)" );
		}
		conn1 = null;
	}
}


